package com.lagou.mr.sv;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class SortValueReducer extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {
    IntWritable rank = new IntWritable(1); //声明一个记录输出排名的变量

    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {

        // 对每个<key, value_list>中的value_list进行遍历，每经过一个value，rank值加1
        for(IntWritable v: values){
            context.write(rank, key);
            rank = new IntWritable(rank.get() + 1);

        }
    }
}
